package servlet;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.entity.CollectionOrder;
import org.entity.OrderInfo;
import org.service.impl.OrderServiceImpl;

/**
 * Servlet implementation class OrderQuery
 */
public class OrderQuery extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	     HttpSession session=request.getSession();
	     String uName=(String)session.getAttribute("username");
	     System.out.println(uName);

	 	OrderServiceImpl IOS=new OrderServiceImpl();
	 		ResultSet rs =IOS.queryByUName(uName);
	 		List<OrderInfo> list=new ArrayList<OrderInfo>();
	 		
	 		try {
	 			while(rs.next()){
	 				OrderInfo oIi= new OrderInfo();
	 				oIi.setOrderid(rs.getInt("ORDERID"));
	 				oIi.setGoodswt(rs.getInt("GOODSWT"));
	 				oIi.setMailfee(rs.getInt("mailfee"));
	 				oIi.setSENDCITY(rs.getString("SENDCITY"));
	 				oIi.setREACHCITY(rs.getString("REACHCITY"));
	 				list.add(oIi);
	 			}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	 		
	 		CollectionOrder co=new CollectionOrder();
	 		co.setList(list);
	 	session.setAttribute("co", co);
	 	request.getRequestDispatcher("order.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
